package com.usian.controller;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.usian.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("/login")
public class LoginController {

    @RequestMapping("/toLogin")
    public String toLogin(){
        return "login";
    }

    @RequestMapping("/login")
    public String login(User user, HttpServletRequest request){
        if(StringUtils.isNotBlank(user.getUserName())&& StringUtils.isNotBlank(user.getPassword())){
            request.getSession().setAttribute("user",user);
            request.getSession().setMaxInactiveInterval(10); //设置session有效期  10s
        }
        return "redirect:/user/findAll";
    }
}
